package com.huike.clues.service.impl;


import com.huike.clues.domain.dto.ClueDetail;
import com.huike.clues.domain.dto.PageList;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 线索跟进记录Service业务层处理
 *
 * @date 2022-04-22
 */
@Service
@RequiredArgsConstructor
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {
    /**
     * ioc注入
     */
    private final TbClueTrackRecordMapper clueTrackRecordMapper;

    @Override
    public void addClue(ClueTrackRecordVo clueTrackRecordVo) {
        String createBy = clueTrackRecordMapper.findCreateBy(clueTrackRecordVo);
        clueTrackRecordVo.setCreateBy(createBy);
        clueTrackRecordMapper.addClue(clueTrackRecordVo);
    }

    @Override
    public PageList findClues(Long clueId) {
        PageList pageList = new PageList();

        List<ClueDetail> clues = clueTrackRecordMapper.findClues(clueId);

        Integer total = clueTrackRecordMapper.findTotal(clueId);
        clues.stream().map(clue -> {
                    clue.setUpdateBy(null);
                    clue.setUpdateTime(null);
                    return clue;
                }
        ).collect(Collectors.toList());
        pageList.setRows(clues);
        pageList.setTotal(total);
        System.out.println(pageList);

        return pageList;
    }
}
